app.controller("examListCtrl",function($scope,$state,$http,$ionicLoading){
    //用户数据
    var user_info = JSON.parse(localStorage.getItem("UserInfo"));
    // var getPath = JSON.parse(localStorage.getItem("getPath"));
    $scope.hasMore = true;
    var currentPageNum = 1;
    $scope.bookLists = [];
    var obj = {
        userId:user_info.userId,
        currentPage:currentPageNum,
        pageSize:10
    };
    angular.element(document).ready(function(){
        $scope.loadMoreLearnList();
    });
    //加载更多
    $scope.loadMoreLearnList = function(){
        $scope.getExamList();
        obj.currentPage=currentPageNum++;
        $scope.$broadcast('scroll.infiniteScrollComplete');
    };
    //获取考试列表
    $scope.getExamList = function () {
        //获取考试列表
        var url = getPath.url+getPath.name+"/app/findCircleList";
        $http({
            url: url,
            method: "POST",
            headers:{'Content-Type':'application/x-www-form-urlencoded'},
            data: obj
        }).success(function (data) {
                if (data.length > 0) {
                    $scope.examListData = data;
                } else if (data.length == 0) {
                    $ionicLoading.show({
                        template: "非考试日期不能开始考试！",
                        duration: 3000
                    });
                    // $state.go("home.educational");
                }else{
                    $ionicLoading.show({
                        template: "获取数据失败，请联系管理员！",
                        duration: 3000
                    });
                    // $state.go("home.educational");
                }

            })
            .error(function () {
                $ionicLoading.hide();
                $ionicLoading.show({
                    template: "获取数据失败，请联系管理员！",
                    duration: 3000
                });
            });
    }
    //进入考试首页
    $scope.openExamFristPage = function (examCode,examName,examEndTime,questionCnt,examUserStatus,examIssueNum) {
        exam_subject.examCode = examCode;
        exam_subject.examName = examName;
        exam_subject.examEndTime = examEndTime;
        exam_subject.questionCnt = questionCnt;
        exam_subject.examIssueNum = examIssueNum;
        // $state.go("home.examSubject");
        //如果没有考试 并且时间过了考试时间 不允许进入
        var isExam = false;
        var examEndTimeDate = new Date(examEndTime.replace(/-/g,"/"));
        var nowDate = new Date();
        if(nowDate>examEndTimeDate){
            isExam = true;
        }
        if(!isExam){
            $ionicLoading.show({
                template: "未到考试时间！",
                duration: 3000
            });
        }else if(examUserStatus == 1 && isExam){
            $state.go("home.examAnalysis");
        }else if(examUserStatus == 0 && isExam){
            $ionicLoading.show({
                template: "您未参加此次考试！",
                duration: 3000
            });
        }else{
            $state.go("home.examOpen");
        }

        // if(examUserStatus == 1){
        //     $state.go("home.examAnalysis");
        // }else{
        //     $state.go("home.examOpen");
        // }

    }
});